home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / 4.2bsd / access.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-12  |  18.0 KB  |  804 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* $XConsortium: access.c,v 1.44 89/11/12 15:38:59 rws Exp $ */
  26.  
  27. #include "Xos.h"
  28. #include "X.h"
  29. #include "Xproto.h"
  30. #include "misc.h"
  31. #include "site.h"
  32. #include <errno.h>
  33. #include <sys/socket.h>
  34. #include <sys/ioctl.h>
  35.  
  36. #ifdef hpux
  37. # include <sys/utsname.h>
  38. # ifdef HAS_IFREQ
  39. #  include <net/if.h>
  40. # endif
  41. #else
  42. # include <net/if.h>
  43. #endif /* hpux */
  44.  
  45. #include <netdb.h>
  46. #ifdef TCPCONN
  47. #include <netinet/in.h>
  48. #endif /* TCPCONN */
  49. #ifdef DNETCONN
  50. #include <netdnet/dn.h>
  51. #include <netdnet/dnetdb.h>
  52. #endif
  53. #undef NULL
  54. #include <stdio.h>
  55. #include "dixstruct.h"
  56. #include "osdep.h"
  57.  
  58. #define acmp(a1, a2, len) bcmp((char *)(a1), (char *)(a2), len)
  59. #define acopy(a1, a2, len) bcopy((char *)(a1), (char *)(a2), len)
  60. #define addrEqual(fam, address, length, host) \
  61.              ((fam) == (host)->family &&\
  62.               (length) == (host)->len &&\
  63.               !acmp (address, (host)->addr, length))
  64.  
  65. #ifdef hpux
  66. #define getpeername(fd, from, fromlen)    hpux_getpeername(fd, from, fromlen)
  67. #endif
  68.  
  69. extern char    *index();
  70.  
  71. static int XFamily(), UnixFamily();
  72. static int ConvertAddr(), CheckAddr();
  73. static void NewHost();
  74.  
  75. typedef struct _host {
  76.     short        family;
  77.     short        len;
  78. #ifdef DNETCONN
  79.     unsigned char    addr[sizeof(struct dn_naddr)];
  80. #else
  81.     unsigned char    addr[4];    /* will need to be bigger eventually */
  82. #endif
  83.     struct _host *next;
  84. } HOST;
  85.  
  86. static HOST *selfhosts = NULL;
  87. static HOST *validhosts = NULL;
  88. static int AccessEnabled = DEFAULT_ACCESS_CONTROL;
  89. static int LocalHostEnabled = FALSE;
  90. static int UsingXdmcp = FALSE;
  91.  
  92. typedef struct {
  93.     int af, xf;
  94. } FamilyMap;
  95.  
  96. static FamilyMap familyMap[] = {
  97. #ifdef     AF_DECnet
  98. #ifdef     DNETCONN
  99.     {AF_DECnet, FamilyDECnet},
  100. #endif
  101. #endif /* AF_DECnet */
  102. #ifdef     AF_CHAOS
  103. #ifdef     CHAOSCONN
  104.     {AF_CHAOS, FamilyChaos},
  105. #endif
  106. #endif /* AF_CHAOS */
  107. #ifdef    AF_INET
  108. #ifdef    TCPCONN
  109.     {AF_INET, FamilyInternet}
  110. #endif
  111. #endif
  112. };
  113.  
  114. /*
  115.  * called when authorization is not enabled to add the
  116.  * local host to the access list
  117.  */
  118.  
  119. EnableLocalHost ()
  120. {
  121.     if (!UsingXdmcp)
  122.     {
  123.     LocalHostEnabled = TRUE;
  124.     AddLocalHosts ();
  125.     }
  126. }
  127.  
  128. /*
  129.  * called at init time when XDMCP will be used; xdmcp always
  130.  * adds local hosts manually when needed
  131.  */
  132.  
  133. AccessUsingXdmcp ()
  134. {
  135.     UsingXdmcp = TRUE;
  136.     LocalHostEnabled = FALSE;
  137. }
  138.  
  139. #define FAMILIES ((sizeof familyMap)/(sizeof familyMap[0]))
  140.  
  141. #if defined (hpux) && ! defined (HAS_IFREQ)
  142. /* Define this host for access control.  Find all the hosts the OS knows about 
  143.  * for this fd and add them to the selfhosts list.
  144.  * HPUX version - hpux does not have SIOCGIFCONF ioctl;
  145.  */
  146. DefineSelf (fd)
  147.     int fd;
  148. {
  149.     register int n;
  150.     int    len;
  151.     caddr_t    addr;
  152.     int        family;
  153.     register HOST    *host;
  154.  
  155.     struct utsname name;
  156.     register struct hostent  *hp;
  157.  
  158.     union {
  159.     struct  sockaddr   sa;
  160.     struct  sockaddr_in  in;
  161.     } saddr;
  162.     
  163.     struct    sockaddr_in    *inetaddr;
  164.  
  165.     /* Why not use gethostname()?  Well, at least on my system, I've had to
  166.      * make an ugly kernel patch to get a name longer than 8 characters, and
  167.      * uname() lets me access to the whole string (it smashes release, you
  168.      * see), whereas gethostname() kindly truncates it for me.
  169.      */
  170.     uname(&name);
  171.     hp = gethostbyname (name.nodename);
  172.     if (hp != NULL)
  173.     {
  174.     saddr.sa.sa_family = hp->h_addrtype;
  175.     inetaddr = (struct sockaddr_in *) (&(saddr.sa));
  176.     acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length);
  177.     len = sizeof(saddr.sa);
  178.     family = ConvertAddr ( &(saddr.sa), &len, &addr);
  179.     if ( family > 0)
  180.     {
  181.         for (host = selfhosts;
  182.          host && !addrEqual (family, addr, len, host);
  183.          host = host->next) ;
  184.         if (!host)
  185.         {
  186.         /* add this host to the host list.    */
  187.         host = (HOST *) xalloc (sizeof (HOST));
  188.         if (host)
  189.         {
  190.             host->family = family;
  191.             host->len = len;
  192.             acopy ( addr, host->addr, len);
  193.             host->next = selfhosts;
  194.             selfhosts = host;
  195.         }
  196.         }
  197.     }
  198.     }
  199. }
  200.  
  201. #else
  202. /* Define this host for access control.  Find all the hosts the OS knows about 
  203.  * for this fd and add them to the selfhosts list.
  204.  */
  205. DefineSelf (fd)
  206.     int fd;
  207. {
  208.     char        buf[2048];
  209.     struct ifconf    ifc;
  210.     register int    n;
  211.     int         len;
  212.     pointer         addr;
  213.     int         family;
  214.     register HOST     *host;
  215.     register struct ifreq *ifr;
  216.     
  217. #ifdef DNETCONN
  218.     struct dn_naddr *dnaddr = getnodeadd(0);
  219.     /*
  220.      * AF_DECnet may not be listed in the interface list.  Instead use
  221.      * the supported library call to find out the local address (if any).
  222.      */
  223.     if (dnaddr)
  224.     {    
  225.     addr = (pointer) dnaddr;
  226.     len = dnaddr->a_len + sizeof(dnaddr->a_len);
  227.     family = AF_DECnet;
  228.     for (host = selfhosts;
  229.          host && !addrEqual (family, addr, len, host);
  230.          host = host->next)
  231.         ;
  232.         if (!host)
  233.     {
  234.         host = (HOST *) xalloc (sizeof (HOST));
  235.         if (host)
  236.         {
  237.         host->family = family;
  238.         host->len = len;
  239.         acopy(addr, host->addr, len);
  240.         host->next = selfhosts;
  241.         selfhosts = host;
  242.         }
  243.     }
  244.     }
  245. #endif
  246.     ifc.ifc_len = sizeof (buf);
  247.     ifc.ifc_buf = buf;
  248.     if (ioctl (fd, (int) SIOCGIFCONF, (pointer) &ifc) < 0)
  249.         Error ("Getting interface configuration");
  250.     for (ifr = ifc.ifc_req, n = ifc.ifc_len / sizeof (struct ifreq); --n >= 0;
  251.      ifr++)
  252.     {
  253.     len = sizeof(ifr->ifr_addr);
  254. #ifdef DNETCONN
  255.     /*
  256.      * DECnet was handled up above.
  257.      */
  258.     if (ifr->ifr_addr.sa_family == AF_DECnet)
  259.         continue;
  260. #endif /* DNETCONN */
  261.         if ((family = ConvertAddr (&ifr->ifr_addr, &len, &addr)) <= 0)
  262.         continue;
  263.         for (host = selfhosts;
  264.           host && !addrEqual (family, addr, len, host);
  265.          host = host->next)
  266.         ;
  267.         if (host)
  268.         continue;
  269.         host = (HOST *) xalloc (sizeof (HOST));
  270.     if (host)
  271.     {
  272.         host->family = family;
  273.         host->len = len;
  274.         acopy(addr, host->addr, len);
  275.         host->next = selfhosts;
  276.         selfhosts = host;
  277.     }
  278. #ifdef XDMCP
  279.     {
  280.         struct sockaddr broad_addr;
  281.  
  282.         /*
  283.          * If this isn't an Internet Address, don't register it.
  284.          */
  285.         if (family != AF_INET)
  286.         continue;
  287.  
  288.         XdmcpRegisterConnection (FamilyInternet, (char *)addr, len);
  289.         broad_addr = ifr->ifr_addr;
  290.         ((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
  291.         htonl (INADDR_BROADCAST);
  292. #ifdef SIOCGIFBRDADDR
  293.         {
  294.             struct ifreq    broad_req;
  295.     
  296.             broad_req = *ifr;
  297.         if (ioctl (fd, SIOCGIFFLAGS, (char *) &broad_req) != -1 &&
  298.             (broad_req.ifr_flags & IFF_BROADCAST) &&
  299.             (broad_req.ifr_flags & IFF_UP)
  300.             )
  301.         {
  302.             broad_req = *ifr;
  303.             if (ioctl (fd, SIOCGIFBRDADDR, &broad_req) != -1)
  304.             broad_addr = broad_req.ifr_addr;
  305.             else
  306.             continue;
  307.         }
  308.         else
  309.             continue;
  310.         }
  311. #endif
  312.         XdmcpRegisterBroadcastAddress ((struct sockaddr_in *) &broad_addr);
  313.     }
  314. #endif
  315.     }
  316. }
  317. #endif /* hpux && !HAS_IFREQ */
  318.  
  319. #ifdef XDMCP
  320. void
  321. AugmentSelf(fd)
  322.     int fd;
  323. {
  324.     int len;
  325.     struct sockaddr from;
  326.     int family;
  327.     pointer addr;
  328.     register HOST *host;
  329.  
  330.     len = sizeof(from);
  331.     if (getpeername(fd, &from, &len))
  332.     return;
  333.     family = ConvertAddr(&from, &len, &addr);
  334.     if (family <= 0)
  335.     return;
  336.     for (host = selfhosts; host; host = host->next)
  337.     {
  338.     if (addrEqual(family, addr, len, host))
  339.         return;
  340.     }
  341.     host = (HOST *)xalloc(sizeof(HOST));
  342.     if (!host)
  343.     return;
  344.     host->family = family;
  345.     host->len = len;
  346.     acopy(addr, host->addr, len);
  347.     host->next = selfhosts;
  348.     selfhosts = host;
  349. }
  350. #endif
  351.  
  352. AddLocalHosts ()
  353. {
  354.     HOST    *self;
  355.  
  356.     for (self = selfhosts; self; self = self->next)
  357.     NewHost (self->family, self->addr, self->len);
  358. }
  359.  
  360. /* Reset access control list to initial hosts */
  361. ResetHosts (display)
  362.     char *display;
  363. {
  364.     register HOST    *host;
  365.     char         hostname[120];
  366.     char        fname[32];
  367.     FILE        *fd;
  368.     char        *ptr;
  369.     union {
  370.         struct sockaddr    sa;
  371. #ifdef TCPCONN
  372.         struct sockaddr_in in;
  373. #endif /* TCPCONN */
  374. #ifdef DNETCONN
  375.         struct sockaddr_dn dn;
  376. #endif
  377.     }             saddr;
  378. #ifdef DNETCONN
  379.     struct nodeent     *np;
  380.     struct dn_naddr     dnaddr, *dnaddrp, *dnet_addr();
  381. #endif
  382.     int            family;
  383.     int            len;
  384.     pointer        addr;
  385.     register struct hostent *hp;
  386.  
  387.     AccessEnabled = DEFAULT_ACCESS_CONTROL;
  388.     LocalHostEnabled = FALSE;
  389.     while (host = validhosts)
  390.     {
  391.         validhosts = host->next;
  392.         xfree (host);
  393.     }
  394.     strcpy (fname, "/etc/X");
  395.     strcat (fname, display);
  396.     strcat (fname, ".hosts");
  397.     if (fd = fopen (fname, "r")) 
  398.     {
  399.         while (fgets (hostname, sizeof (hostname), fd))
  400.     {
  401.         if (ptr = index (hostname, '\n'))
  402.             *ptr = 0;
  403. #ifdef DNETCONN
  404.         if ((ptr = index (hostname, ':')) && (*(ptr + 1) == ':'))
  405.     {
  406.             /* node name (DECnet names end in "::") */
  407.             *ptr = 0;
  408.         dnaddrp = dnet_addr(hostname);
  409.             if (!dnaddrp && (np = getnodebyname (hostname)))
  410.         {
  411.         /* node was specified by name */
  412.         saddr.sa.sa_family = np->n_addrtype;
  413.         len = sizeof(saddr.sa);
  414.         if (ConvertAddr (&saddr.sa, &len, &addr) == AF_DECnet)
  415.         {
  416.             bzero ((char *) &dnaddr, sizeof (dnaddr));
  417.             dnaddr.a_len = np->n_length;
  418.             acopy (np->n_addr, dnaddr.a_addr, np->n_length);
  419.             dnaddrp = &dnaddr;
  420.         }
  421.             }
  422.         if (dnaddrp)
  423.         NewHost((short)AF_DECnet, (pointer)dnaddrp,
  424.             (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len)));
  425.         }
  426.     else
  427.     {
  428. #endif /* DNETCONN */
  429. #ifdef TCPCONN
  430.             /* host name */
  431.             if (hp = gethostbyname (hostname))
  432.         {
  433.             saddr.sa.sa_family = hp->h_addrtype;
  434.         len = sizeof(saddr.sa);
  435.             if ((family = ConvertAddr (&saddr.sa, &len, &addr)) > 0)
  436. #ifdef h_addr                /* new 4.3bsd version of gethostent */
  437.         {
  438.             char **list;
  439.  
  440.             /* iterate over the addresses */
  441.             for (list = hp->h_addr_list; *list; list++)
  442.             NewHost (family, (pointer)*list, len);
  443.         }
  444. #else
  445.                 NewHost (family, (pointer)hp->h_addr, len);
  446. #endif
  447.  
  448.             }
  449. #endif /* TCPCONN */
  450. #ifdef DNETCONN
  451.         }    
  452. #endif /* DNETCONN */
  453.         }
  454.         fclose (fd);
  455.     }
  456. }
  457.  
  458. static Bool
  459. AuthorizedClient(client)
  460.     ClientPtr client;
  461. {
  462.     int            alen, family;
  463.     struct sockaddr    from;
  464.     pointer        addr;
  465.     register HOST    *host;
  466.  
  467.     alen = sizeof (from);
  468.     if (!getpeername (((OsCommPtr)client->osPrivate)->fd, &from, &alen))
  469.     {
  470.         if ((family = ConvertAddr (&from, &alen, &addr)) >= 0)
  471.     {
  472.         if (family == 0)
  473.         return TRUE;
  474.         for (host = selfhosts; host; host = host->next)
  475.         {
  476.         if (addrEqual (family, addr, alen, host))
  477.             return TRUE;
  478.         }
  479.     }
  480.     }
  481.     return FALSE;
  482. }
  483.  
  484. /* Add a host to the access control list.  This is the external interface
  485.  * called from the dispatcher */
  486.  
  487. int
  488. AddHost (client, family, length, pAddr)
  489.     ClientPtr        client;
  490.     int                 family;
  491.     unsigned            length;        /* of bytes in pAddr */
  492.     pointer             pAddr;
  493. {
  494.     int            len;
  495.     register HOST    *host;
  496.     int                 unixFamily;
  497.  
  498.     if (!AuthorizedClient(client))
  499.     return(BadAccess);
  500.     unixFamily = UnixFamily(family);
  501.     if (unixFamily < 0)
  502.     {
  503.     client->errorValue = family;
  504.     return (BadValue);
  505.     }
  506.     if ((len = CheckAddr (unixFamily, pAddr, length)) < 0)
  507.     {
  508.     client->errorValue = length;
  509.         return (BadValue);
  510.     }
  511.     for (host = validhosts; host; host = host->next)
  512.     {
  513.         if (addrEqual (unixFamily, pAddr, len, host))
  514.             return (Success);
  515.     }
  516.     host = (HOST *) xalloc (sizeof (HOST));
  517.     if (!host)
  518.     return(BadAlloc);
  519.     host->family = unixFamily;
  520.     host->len = len;
  521.     acopy(pAddr, host->addr, len);
  522.     host->next = validhosts;
  523.     validhosts = host;
  524.     return (Success);
  525. }
  526.  
  527. /* Add a host to the access control list. This is the internal interface 
  528.  * called when starting or resetting the server */
  529. static void
  530. NewHost (family, addr, len)
  531.     short    family;
  532.     pointer    addr;
  533.     int        len;
  534. {
  535.     register HOST *host;
  536.  
  537.     for (host = validhosts; host; host = host->next)
  538.     {
  539.         if (addrEqual (family, addr, len, host))
  540.         return;
  541.     }
  542.     host = (HOST *) xalloc (sizeof (HOST));
  543.     if (host)
  544.     {
  545.     host->family = family;
  546.     host->len = len;
  547.     acopy(addr, host->addr, len);
  548.     host->next = validhosts;
  549.     validhosts = host;
  550.     }
  551. }
  552.  
  553. /* Remove a host from the access control list */
  554.  
  555. int
  556. RemoveHost (client, family, length, pAddr)
  557.     ClientPtr        client;
  558.     int                 family;
  559.     unsigned            length;        /* of bytes in pAddr */
  560.     pointer             pAddr;
  561. {
  562.     int            len,
  563.                         unixFamily;
  564.     register HOST    *host, **prev;
  565.  
  566.     if (!AuthorizedClient(client))
  567.     return(BadAccess);
  568.     unixFamily = UnixFamily(family);
  569.     if (unixFamily < 0)
  570.     {
  571.     client->errorValue = family;
  572.         return(BadValue);
  573.     }
  574.     if ((len = CheckAddr (unixFamily, pAddr, length)) < 0)
  575.     {
  576.     client->errorValue = length;
  577.         return(BadValue);
  578.     }
  579.     for (prev = &validhosts;
  580.          (host = *prev) && (!addrEqual (unixFamily, pAddr, len, host));
  581.          prev = &host->next)
  582.         ;
  583.     if (host)
  584.     {
  585.         *prev = host->next;
  586.         xfree (host);
  587.     }
  588.     return (Success);
  589. }
  590.  
  591. /* Get all hosts in the access control list */
  592. int
  593. GetHosts (data, pnHosts, pLen, pEnabled)
  594.     pointer        *data;
  595.     int            *pnHosts;
  596.     int            *pLen;
  597.     BOOL        *pEnabled;
  598. {
  599.     int            len;
  600.     register int     n = 0;
  601.     register pointer    ptr;
  602.     register HOST    *host;
  603.     int            nHosts = 0;
  604.     int            *lengths = (int *) NULL;
  605.     int            *newlens;
  606.  
  607.     *pEnabled = AccessEnabled ? EnableAccess : DisableAccess;
  608.     for (host = validhosts; host; host = host->next)
  609.     {
  610.     newlens = (int *) xrealloc(lengths, (nHosts + 1) * sizeof(int));
  611.     if (!newlens)
  612.     {
  613.         xfree(lengths);
  614.         return(BadAlloc);
  615.     }
  616.     lengths = newlens;
  617.     lengths[nHosts++] = host->len;
  618.     n += (((host->len + 3) >> 2) << 2) + sizeof(xHostEntry);
  619.     }
  620.     if (n)
  621.     {
  622.         *data = ptr = (pointer) xalloc (n);
  623.     if (!ptr)
  624.     {
  625.         xfree(lengths);
  626.         return(BadAlloc);
  627.     }
  628.     nHosts = 0;
  629.         for (host = validhosts; host; host = host->next)
  630.     {
  631.  
  632.         len = lengths[nHosts++];
  633.         ((xHostEntry *)ptr)->family = XFamily(host->family);
  634.         ((xHostEntry *)ptr)->length = len;
  635.         ptr += sizeof(xHostEntry);
  636.         acopy (host->addr, ptr, len);
  637.         ptr += ((len + 3) >> 2) << 2;
  638.         }
  639.     } else {
  640.     *data = NULL;
  641.     }
  642.     *pnHosts = nHosts;
  643.     *pLen = n;
  644.     xfree(lengths);
  645.     return(Success);
  646. }
  647.  
  648. /* Check for valid address family and length, and return address length. */
  649.  
  650. /*ARGSUSED*/
  651. static int
  652. CheckAddr (family, pAddr, length)
  653.     int            family;
  654.     pointer        pAddr;
  655.     unsigned        length;
  656. {
  657.     int    len;
  658.  
  659.     switch (family)
  660.     {
  661. #ifdef TCPCONN
  662.       case AF_INET:
  663.     if (length == sizeof (struct in_addr))
  664.         len = length;
  665.     else
  666.         len = -1;
  667.         break;
  668. #endif 
  669. #ifdef DNETCONN
  670.       case AF_DECnet:
  671.         {
  672.         struct dn_naddr *dnaddr = (struct dn_naddr *) pAddr;
  673.  
  674.         if ((length < sizeof(dnaddr->a_len)) ||
  675.         (length < dnaddr->a_len + sizeof(dnaddr->a_len)))
  676.         len = -1;
  677.         else
  678.         len = dnaddr->a_len + sizeof(dnaddr->a_len);
  679.         if (len > sizeof(struct dn_naddr))
  680.         len = -1;
  681.     }
  682.         break;
  683. #endif
  684.       default:
  685.         len = -1;
  686.     }
  687.     return (len);
  688. }
  689.  
  690. /* Check if a host is not in the access control list. 
  691.  * Returns 1 if host is invalid, 0 if we've found it. */
  692.  
  693. InvalidHost (saddr, len)
  694.     register struct sockaddr    *saddr;
  695.     int                len;
  696. {
  697.     int             family;
  698.     pointer            addr;
  699.     register HOST         *selfhost, *host;
  700.  
  701.     if (!AccessEnabled)   /* just let them in */
  702.         return(0);    
  703.     if ((family = ConvertAddr (saddr, &len, &addr)) < 0)
  704.         return (1);
  705.     if (family == 0)
  706.     {
  707.     if (!LocalHostEnabled)
  708.      {
  709.         /*
  710.          * check to see if any local address is enabled.  This 
  711.          * implicitly enables local connections.
  712.          */
  713.         for (selfhost = selfhosts; selfhost; selfhost=selfhost->next)
  714.          {
  715.         for (host = validhosts; host; host=host->next)
  716.         {
  717.             if (addrEqual (selfhost->family, selfhost->addr,
  718.                    selfhost->len, host))
  719.             return 0;
  720.         }
  721.         }
  722.         return 1;
  723.     } else
  724.         return (0);
  725.     }
  726.     for (host = validhosts; host; host = host->next)
  727.     {
  728.         if (addrEqual (family, addr, len, host))
  729.             return (0);
  730.     }
  731.     return (1);
  732. }
  733.  
  734. static int
  735. ConvertAddr (saddr, len, addr)
  736.     register struct sockaddr    *saddr;
  737.     int                *len;
  738.     pointer            *addr;
  739. {
  740.     if (*len == 0)
  741.         return (0);
  742.     switch (saddr->sa_family)
  743.     {
  744.       case AF_UNSPEC:
  745. #ifdef UNIXCONN
  746.       case AF_UNIX:
  747. #endif
  748.         return (0);
  749.  
  750. #ifdef TCPCONN
  751.       case AF_INET:
  752.         *len = sizeof (struct in_addr);
  753.         *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr);
  754.         return (AF_INET);
  755. #endif
  756.  
  757. #ifdef DNETCONN
  758.       case AF_DECnet:
  759.     {
  760.         struct sockaddr_dn *sdn = (struct sockaddr_dn *) saddr;
  761.         *len = sdn->sdn_nodeaddrl + sizeof(sdn->sdn_nodeaddrl);
  762.         *addr = (pointer) &(sdn->sdn_add);
  763.     }
  764.         return (AF_DECnet);
  765. #endif
  766.  
  767.       default:
  768.         break;
  769.     }
  770.     return (-1);
  771. }
  772.  
  773. int
  774. ChangeAccessControl(client, fEnabled)
  775.     ClientPtr client;
  776.     int fEnabled;
  777. {
  778.     if (!AuthorizedClient(client))
  779.     return BadAccess;
  780.     AccessEnabled = fEnabled;
  781.     return Success;
  782. }
  783.  
  784. static int XFamily(af)
  785.     int af;
  786. {
  787.     int i;
  788.     for (i = 0; i < FAMILIES; i++)
  789.         if (familyMap[i].af == af)
  790.             return familyMap[i].xf;
  791.     return -1;
  792. }
  793.  
  794. static int UnixFamily(xf)
  795.     int xf;
  796. {
  797.     int i;
  798.     for (i = 0; i < FAMILIES; i++)
  799.         if (familyMap[i].xf == xf)
  800.             return familyMap[i].af;
  801.     return -1;
  802. }
  803.  
  804.